package com.trkj.focusonzhuzhou.tipoff;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.cache.LruDiskCache.Snapshot;
import com.trkj.focusonzhuzhou.R;
import com.trkj.focusonzhuzhou.tipoffAdapter.TipoffCommentsAdapter;

public class NewActivity extends Activity {
	private ImageView share_img;
	public ListView listview;
	public List<Comments> list = new ArrayList<Comments>();
	public EditText Commentsed;
	public Button send;
	public TextView textcommentsq;
	public LinearLayout lin;
	public LinearLayout lintext;

	private int month;
	int day;
	int h;
	int m;
	int s;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newactivity_jump);

		getActionBar().hide();

		listview = (ListView) findViewById(R.id.comments_id);

		lin = (LinearLayout) findViewById(R.id.linlout_id);

		lintext = (LinearLayout) findViewById(R.id.lintext_id);

		Commentsed = (EditText) findViewById(R.id.edcomments_id);

		Button send = (Button) findViewById(R.id.sendbtn_id);

		TextView textcommentsq = (TextView) findViewById(R.id.textcommentsq_id);

		ImageView shareimg = (ImageView) findViewById(R.id.share_img);

		TipoffCommentsAdapter adapter = new TipoffCommentsAdapter(this, list);

		listview.setAdapter(adapter);

		send.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String commentcontent = Commentsed.getText().toString();

				String users = "我是好人";

				Comments commentz = new Comments();

				commentz.users = users;

				commentz.edcontent = commentcontent;

				SimpleDateFormat sdf = new SimpleDateFormat(
						"yyyy-MM-dd HH-mm-ss");

				Calendar cal = Calendar.getInstance();
				cal.setTime(new Date());
				month = cal.get(cal.MONTH);
				day = cal.get(cal.DAY_OF_MONTH);
				h = cal.get(cal.HOUR_OF_DAY);
				m = cal.get(cal.MINUTE);
				s = cal.get(cal.SECOND);
				commentz.time = (month + 1) + "-" + day + " " + h + ":" + m + ":" + s;

				list.add(0, commentz);

				TipoffCommentsAdapter adapter = (TipoffCommentsAdapter) listview
						.getAdapter();

				adapter.notifyDataSetChanged();

				in();
			}

		});

		textcommentsq.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

				lintext.setVisibility(lintext.GONE);

				lin.setVisibility(lin.VISIBLE);
				Commentsed.requestFocus();

				InputMethodManager imm = (InputMethodManager) Commentsed
						.getContext().getSystemService(
								NewActivity.this.INPUT_METHOD_SERVICE);

				imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);

			}
		});

		shareimg.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_SEND);
				intent.setType("image/text");
				intent.putExtra(Intent.EXTRA_SUBJECT, "鍒嗕韩");
				intent.putExtra(Intent.EXTRA_TEXT, "文字");
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(Intent.createChooser(intent, getTitle()));
			}
		});

	}

	public void in() {
		lintext.setVisibility(lintext.VISIBLE);
		lin.setVisibility(lin.GONE);
		InputMethodManager imm = (InputMethodManager) getSystemService(NewActivity.this.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(Commentsed.getWindowToken(), 0);
	}

	public void goBack(View view) {
		this.finish();
	}
}
